<?php 
require_once('BaseTransactionReportForm.class.php');
class EmployeeLeavesReportForm extends BaseTransactionReportForm
{

    public function configure(){
        parent::configure();

        $this->widgetSchema['card_id'] =  new sfWidgetFormInput();
        $this->validatorSchema['card_id'] =  new sfValidatorString(array('required'=>false));

        $this->widgetSchema['created_at'] = new sfWidgetFormDateWithWeek();

        $this->validatorSchema['created_at'] = new sfValidatorDateWithWeek(array('required'=>false));
        $this->getWidgetSchema()->setLabel('created_at','Transaction period');
        $this->getWidgetSchema()->setHelp('created_at','Week / Month / Year');

        $this->getWidgetSchema()->moveField('card_id','after','employee_id');
        $this->getWidgetSchema()->moveField('created_at','after','card_id');

        
        
        
        unset($this['department_id'],$this['section_id']);

    }
    
    
    public function addCreatedAtColumnCriteria(Criteria $criteria , $field , $value){
        if(is_array($value) && count($value) > 0){
        	$ctn = $criteria->getNewCriterion(TransactionPeer::DATE_FROM ,$value[0] , Criteria::GREATER_EQUAL );
        	$ctn2 = $criteria->getNewCriterion(TransactionPeer::DATE_FROM ,$value[1] , Criteria::LESS_EQUAL  );
        	$ctn->addAnd($ctn2);
        	$criteria->add($ctn);
        }
    }
        
    public function addLeaveStartColumnCriteria(Criteria $criteria , $field , $value){
        sfConfig::set( 'criteria_leave_start_time' , $value );
    }
    
    public function getDisplayFields(){
        $fields = parent::getDisplayFields();
        
        $fields = array_merge($fields,array('date'=>'Date'));
        //var_dump($fields);exit;
        return $fields;
    }
    
    public function addLeaveEndColumnCriteria( Criteria $criteria , $field , $value ){
        $start_time = sfConfig::get( 'criteria_leave_start_time' ) ;
        $end_time   = $value ;
        
        $time1 = strtotime('2010-01-01 '.$start_time);
        $time2 = strtotime('2010-01-01 '.$end_time);
        
        if($start_time && $end_time && $time2 > $time1 ){
            $sql  = " ( time('{$start_time}') <= time(".TransactionPeer::DATE_FROM.")";
            $sql .= " AND time('{$end_time}') >= time(".TransactionPeer::DATE_TO.") )";
           $criteria->add( TransactionPeer::DATE_FROM , $sql , Criteria::CUSTOM );
        }
    }
}



